<?php
class ControllerWebFriend extends Controller {
	public function index() {
		$this->load->language('web/index');
		
		$this->document->setTitle('Friend Link');
		
		$this->data['heading_title'] = 'Friend Link';
		
		if (isset($this->error['warning'])) {
			$this->data['error_warning'] = $this->error['warning'];
		}
		else {
			$this->data['error_warning'] = '';
		}
		
		if (isset($this->error['name'])) {
			$this->data['error_name'] = $this->error['name'];
		}
		else {
			$this->data['error_name'] = array();
		}
		
		if (isset($this->error['meta_description'])) {
			$this->data['error_meta_description'] = $this->error['meta_description'];
		}
		else {
			$this->data['error_meta_description'] = array();
		}
		
		if (isset($this->error['description'])) {
			$this->data['error_description'] = $this->error['description'];
		}
		else {
			$this->data['error_description'] = array();
		}
		
		if (isset($this->error['model'])) {
			$this->data['error_model'] = $this->error['model'];
		}
		else {
			$this->data['error_model'] = '';
		}
		
		if (isset($this->error['date_available'])) {
			$this->data['error_date_available'] = $this->error['date_available'];
		}
		else {
			$this->data['error_date_available'] = '';
		}
		if (isset($this->session->data['success'])) {
			$this->data['success'] = $this->session->data['success'];
			
			unset($this->session->data['success']);
		}
		else {
			$this->data['success'] = '';
		}
		
		$this->data['token'] = $this->session->data['token'];
		
		if (isset($this->request->get['page'])) {
			$page = $this->request->get['page'];
		}
		else {
			$page = 1;
		}
		
		$url = '';
		
		if (isset($this->request->get['sort'])) {
			$url .= '&sort=' . $this->request->get['sort'];
		}
		
		if (isset($this->request->get['order'])) {
			$url .= '&order=' . $this->request->get['order'];
		}
		
		if (isset($this->request->get['page'])) {
			$url .= '&page=' . $this->request->get['page'];
		}
		
		$this->data['breadcrumbs'] = array();
		
		$this->data['breadcrumbs'][] = array( 
			'text' => $this->language->get('text_home'), 
			'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'), 
			'separator' => false 
		);
		
		$this->data['breadcrumbs'][] = array( 
			'text' => $this->language->get('heading_title'), 
			'href' => $this->url->link('web/index', 'token=' . $this->session->data['token'] . $url, 'SSL'), 
			'separator' => ' :: ' 
		);
		$this->load->model('web/index');
		$friends = $this->model_web_index->getFriend($this->request->get);
		$friend_num = $this->model_web_index->getFriendTotal();
		$this->data['friends'] = $friends;
		$pagination = new Pagination();
		$pagination->total = $friend_num;
		$pagination->page = $page;
		$pagination->limit = $this->config->get('config_admin_limit');
		$pagination->text = $this->language->get('text_pagination');
		$pagination->url = $this->url->link('web/friend', 'token=' . $this->session->data['token'] . $url . '&page={page}', 'SSL');
		
		$this->data['pagination'] = $pagination->render();
		
		$this->template = 'web/friend.tpl';
		$this->children = array( 
			'common/header', 
			'common/footer' 
		);
		
		$this->response->setOutput($this->render());
	}
	public function update() {
		$this->load->model('web/index');
		echo $this->model_web_index->updateFriend($this->request->post);
	}
	
	public function del() {
		$this->load->model('web/index');
		$id=$this->request->post['id'];
		echo $this->model_web_index->delFriend($id);
	}
}